//
//  ViewController.m
//  04-UIControl
//
//  Created by dllo on 16/7/19.
//  Copyright © 2016年 LST. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    // UISwitch 开关
    // 宽高不影响控件的大小, 只有x和y
    UISwitch *switchControl = [[UISwitch alloc]initWithFrame:CGRectMake(100, 100, 0, 0)];
    // 中间圆形的颜色
    switchControl.thumbTintColor = [UIColor yellowColor];
    // 开启时的控件 内部颜色
    switchControl.onTintColor = [UIColor greenColor];
    // 边框及切换到关闭时的颜色
    switchControl.tintColor = [UIColor cyanColor];
    // 打开时的图片 iOS7后失效
    switchControl.onImage = [UIImage imageNamed:@"guidePage_01 "];
    // 关闭时的图片, iOS7后失效
    switchControl.offImage = [UIImage imageNamed:@"guidePage_01 "];
    // 判断开始是开的还是关的
    // 通过set方法改变switchControl的初始状态
    switchControl.on = YES;
    // 判断switch的开关状态
    NSLog(@"%@", switchControl.isOn ? @"YES" : @"NO");
    [switchControl setOn:YES animated:YES];
    [self.view addSubview:switchControl];
    // 添加绑定事件 与Button相同
    [switchControl addTarget:self action:@selector(clickSwitch:) forControlEvents:UIControlEventValueChanged];
    
    // UISlider
    // 高度不影响视图的高度, 这个控件永远居中于视图中间
    UISlider *slider = [[UISlider alloc] initWithFrame:CGRectMake(0, 200, 375, 50)];
    // slider.backgroundColor = [UIColor blackColor];
    // 1.当前滑块的值
    slider.value = 0.5f;
    // 2.滑块最小值
    slider.minimumValue = 0.0f;
    // 3.滑块最大值
    slider.maximumValue = 1.0f;
    // 4.以上最大和最小可以根据需求去改变
    // slider.continuous = NO;
    // 5.已经移动到的区域颜色
    // slider.minimumTrackTintColor = [UIColor yellowColor];
    // 6.未移动到的区域颜色
    // slider.maximumTrackTintColor = [UIColor greenColor];
    // 7.滑块的颜色
    // slider.thumbTintColor = [UIColor cyanColor];
    // 8.最小那边显示的图片
    // slider.minimumValueImage = [UIImage imageNamed:@"guidePage_01"];
    // 9.slider 最大那边显示的图片
    // slider.maximumValueImage = [UIImage imageNamed:@"guidePage_01"];
    // 10.yes 连续触发 NO 离开的时候触发
    slider.continuous = YES;
    [self.view addSubview:slider];
    // 滑块的图片
    [slider setThumbImage:[UIImage imageNamed:@"player_slider_playback_thumb"] forState:UIControlStateNormal];
    // 进度条滑块左面的图片
    [slider setMinimumTrackImage:[UIImage imageNamed:@"player_slider_playback_left"] forState:UIControlStateNormal];
    // 进度条滑块右面的图片
    [slider setMaximumTrackImage:[UIImage  imageNamed:@"player_slider_playback_right"] forState:UIControlStateNormal];
    // 绑定事件
    [slider addTarget:self action:@selector(clickSlider:) forControlEvents:UIControlEventValueChanged];
    
    UISegmentedControl *segmented = [[UISegmentedControl alloc] initWithItems:@[@"first", @"secont",@"last"]];
    // segment不给frame 系统会自动计算大小(推荐: 加上frame)
    segmented.frame = CGRectMake(20, 20, 335, 50);
    NSLog(@"%@", NSStringFromCGRect(segmented.frame));
    // momentary 默认为NO 显示选中状态 设置为YES 如果点击选中没有选中状态
    segmented.momentary = NO;
    segmented.tag = 1001;
    // 绑定事件 addTar
    // numberOfSegments 分段控制器的item个数
    NSUInteger number = segmented.numberOfSegments;
    NSLog(@"分段控制器的段数%lu",number);
    // 插入一个item
    // [segmented insertSegmentWithTitle:@"1" atIndex:1 animated:YES];
    // 删除 remove
    // setTitle:forSegmentAtIndex: 用来修改对应下标的标题
    // [segmented setTitle:@"黄晓" forSegmentAtIndex:0];
    // setWidth:forSegmentAtIndex: width默认为0
    [segmented setWidth:0 forSegmentAtIndex:0];
    // 设置对应下标内容的偏移
    // [segmented setContentOffset:CGSizeMake(0, 20) forSegmentAtIndex:0];
    // setEnabled是否被选中
    [segmented setEnabled:YES forSegmentAtIndex:0];
    // 改变segment文字及边框颜色
    // segmented.tintColor = [UIColor whiteColor];
    // selectedSegmentIndex 选中的下标
    segmented.selectedSegmentIndex = 1;
    // 练习 点击Button 使segment 添加新标题
    // apportionsSegmentWidthsByContent 默认为no 如果分段控制器的段宽为0时 并且这个属性设为yes 系统会自动计算
    segmented.apportionsSegmentWidthsByContent = YES;
    [self.view addSubview:segmented];
    
    UIButton *btn = [UIButton  buttonWithType:UIButtonTypeCustom];
    [btn setTitle:@"添加" forState:UIControlStateNormal];
    [btn setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
    btn.frame = CGRectMake(20, 400, 375, 200);
    [self.view addSubview:btn];
    [btn addTarget:self action:@selector(clickAddSegment:) forControlEvents:UIControlEventTouchUpInside];
    UIPageControl *page = [[UIPageControl alloc] initWithFrame:CGRectMake(0, 550, 200, 50)];
    // 1.分页控制器的页数
    page.numberOfPages = 5;
    // 2.当前页数
    page.currentPage = 0;
    // page.backgroundColor = [UIColor blackColor];
    // 3.hidesForSinglePage 当只有一页时,隐藏 默认为NO
    page.hidesForSinglePage = YES;
    // 4.
   CGSize size = [page sizeForNumberOfPages:0];
    NSLog(@"%@", NSStringFromCGSize(size));
    //    page.defersCurrentPageDisplay = YES;
    // 5.未选中页的默认颜色
    page.pageIndicatorTintColor = [UIColor greenColor];
    // 6.当前页的颜色
    page.currentPageIndicatorTintColor = [UIColor redColor];
    // 8.关闭系统事件page的切换,直到调用updateCurrentPageDisplay方法 才会显示
    page.defersCurrentPageDisplay = YES;
    [self.view addSubview:page];
    // 7.绑定事件
    [page addTarget:self action:@selector(clickPage:) forControlEvents:UIControlEventValueChanged];
}
// switch触发的事件
- (void)clickSwitch:(UISwitch *)switchControl {
    // 根据switch的状态决定触发设么样的事件
    if (switchControl.on == YES) {
        NSLog(@"开");
    } else {
        NSLog(@"关");
    }
}
- (void)clickSlider:(UISlider *) slider {
    NSLog(@"%f", slider.value);
}
- (void)clickAddSegment:(UIButton *)sender {
    UISegmentedControl *segment = [self.view viewWithTag:1001];
    [segment insertSegmentWithTitle:@"huang" atIndex:1 animated:YES];
}
- (void)clickPage:(UIPageControl *)page {
    NSLog(@"change");
    [page updateCurrentPageDisplay];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
